<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Eigen: Eigen::Ref&lt; PlainObjectType, Options, StrideType &gt; Class Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
  $(document).ready(function() { init_search(); });
/* @license-end */
</script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="eigendoxy.css" rel="stylesheet" type="text/css">
<!--  -->
<script type="text/javascript" src="eigen_navtree_hacks.js"></script>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="Eigen_Silly_Professor_64x64.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname"><a href="http://eigen.tuxfamily.org">Eigen</a>
   &#160;<span id="projectnumber">3.4.90 (git rev 67eeba6e720c5745abc77ae6c92ce0a44aa7b7ae)</span>
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.svg"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.svg" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('classEigen_1_1Ref.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="classEigen_1_1Ref-members.html">List of all members</a> &#124;
<a href="#pub-methods">Public Member Functions</a>  </div>
  <div class="headertitle">
<div class="title">Eigen::Ref&lt; PlainObjectType, Options, StrideType &gt; Class Template Reference<div class="ingroups"><a class="el" href="group__DenseMatrixManipulation__chapter.html">Dense matrix and array manipulation</a> &raquo; <a class="el" href="group__DenseMatrixManipulation__Reference.html">Reference</a> &raquo; <a class="el" href="group__Core__Module.html">Core module</a></div></div>  </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template&lt;typename PlainObjectType, int Options, typename StrideType&gt;<br />
class Eigen::Ref&lt; PlainObjectType, Options, StrideType &gt;</h3>

<p>A matrix or vector expression mapping an existing expression. </p>
<dl class="tparams"><dt>Template Parameters</dt><dd>
  <table class="tparams">
    <tr><td class="paramname">PlainObjectType</td><td>the equivalent matrix type of the mapped data </td></tr>
    <tr><td class="paramname">Options</td><td>specifies the pointer alignment in bytes. It can be: <code><a class="el" href="group__enums.html#gga45fe06e29902b7a2773de05ba27b47a1a60057da2408e499b5656244d0b26cc20">Aligned128</a></code>, , <code><a class="el" href="group__enums.html#gga45fe06e29902b7a2773de05ba27b47a1a2639cfa1e8faac751556bc0009fe95a4">Aligned64</a></code>, <code><a class="el" href="group__enums.html#gga45fe06e29902b7a2773de05ba27b47a1a8a380b1cd0c3e5a6cceac06f8235157a">Aligned32</a></code>, <code><a class="el" href="group__enums.html#gga45fe06e29902b7a2773de05ba27b47a1ad0b140cd97bc74365b51843d28379655">Aligned16</a></code>, <code><a class="el" href="group__enums.html#gga45fe06e29902b7a2773de05ba27b47a1a9d99d7a9ff1da5c949bec22733bfba14">Aligned8</a></code> or <code><a class="el" href="group__enums.html#gga45fe06e29902b7a2773de05ba27b47a1a4e19dd09d5ff42295ba1d72d12a46686">Unaligned</a></code>. The default is <code><a class="el" href="group__enums.html#gga45fe06e29902b7a2773de05ba27b47a1a4e19dd09d5ff42295ba1d72d12a46686">Unaligned</a></code>. </td></tr>
    <tr><td class="paramname">StrideType</td><td>optionally specifies strides. By default, <a class="el" href="classEigen_1_1Ref.html" title="A matrix or vector expression mapping an existing expression.">Ref</a> implies a contiguous storage along the inner dimension (inner stride==1), but accepts a variable outer stride (leading dimension). This can be overridden by specifying strides. The type passed here must be a specialization of the <a class="el" href="classEigen_1_1Stride.html" title="Holds strides information for Map.">Stride</a> template, see examples below.</td></tr>
  </table>
  </dd>
</dl>
<p>This class provides a way to write non-template functions taking <a class="el" href="namespaceEigen.html" title="Namespace containing all symbols from the Eigen library.">Eigen</a> objects as parameters while limiting the number of copies. A Ref&lt;&gt; object can represent either a const expression or a l-value: </p><div class="fragment"><div class="line"><span class="comment">// in-out argument:</span></div>
<div class="line"><span class="keywordtype">void</span> foo1(Ref&lt;VectorXf&gt; x);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// read-only const argument:</span></div>
<div class="line"><span class="keywordtype">void</span> foo2(<span class="keyword">const</span> Ref&lt;const VectorXf&gt;&amp; x);</div>
</div><!-- fragment --><p>In the in-out case, the input argument must satisfy the constraints of the actual Ref&lt;&gt; type, otherwise a compilation issue will be triggered. By default, a Ref&lt;VectorXf&gt; can reference any dense vector expression of float having a contiguous memory layout. Likewise, a Ref&lt;MatrixXf&gt; can reference any column-major dense matrix expression of float whose column's elements are contiguously stored with the possibility to have a constant space in-between each column, i.e. the inner stride must be equal to 1, but the outer stride (or leading dimension) can be greater than the number of rows.</p>
<p>In the const case, if the input expression does not match the above requirement, then it is evaluated into a temporary before being passed to the function. Here are some examples: </p><div class="fragment"><div class="line"><a class="code" href="group__matrixtypedefs.html#ga731599f782380312960376c43450eb48">MatrixXf</a> A;</div>
<div class="line"><a class="code" href="group__matrixtypedefs.html#ga8028d921d43acd5605eabad41c254ef2">VectorXf</a> a;</div>
<div class="line">foo1(a.head());             <span class="comment">// OK</span></div>
<div class="line">foo1(A.col());              <span class="comment">// OK</span></div>
<div class="line">foo1(A.row());              <span class="comment">// Compilation error because here innerstride!=1</span></div>
<div class="line">foo2(A.row());              <span class="comment">// Compilation error because A.row() is a 1xN object while foo2 is expecting a Nx1 object</span></div>
<div class="line">foo2(A.row().transpose());  <span class="comment">// The row is copied into a contiguous temporary</span></div>
<div class="line">foo2(2*a);                  <span class="comment">// The expression is evaluated into a temporary</span></div>
<div class="line">foo2(A.col().segment(2,4)); <span class="comment">// No temporary</span></div>
<div class="ttc" id="agroup__matrixtypedefs_html_ga731599f782380312960376c43450eb48"><div class="ttname"><a href="group__matrixtypedefs.html#ga731599f782380312960376c43450eb48">Eigen::MatrixXf</a></div><div class="ttdeci">Matrix&lt; float, Dynamic, Dynamic &gt; MatrixXf</div><div class="ttdoc">Dynamic×Dynamic matrix of type float.</div><div class="ttdef"><b>Definition:</b> Matrix.h:500</div></div>
<div class="ttc" id="agroup__matrixtypedefs_html_ga8028d921d43acd5605eabad41c254ef2"><div class="ttname"><a href="group__matrixtypedefs.html#ga8028d921d43acd5605eabad41c254ef2">Eigen::VectorXf</a></div><div class="ttdeci">Matrix&lt; float, Dynamic, 1 &gt; VectorXf</div><div class="ttdoc">Dynamic×1 vector of type float.</div><div class="ttdef"><b>Definition:</b> Matrix.h:500</div></div>
</div><!-- fragment --><p>The range of inputs that can be referenced without temporary can be enlarged using the last two template parameters. Here is an example accepting an innerstride!=1: </p><div class="fragment"><div class="line"><span class="comment">// in-out argument:</span></div>
<div class="line"><span class="keywordtype">void</span> foo3(Ref&lt;<a class="code" href="group__matrixtypedefs.html#ga8028d921d43acd5605eabad41c254ef2">VectorXf</a>,0,InnerStride&lt;&gt; &gt; x);</div>
<div class="line">foo3(A.row());              <span class="comment">// OK</span></div>
</div><!-- fragment --><p> The downside here is that the function foo3 might be significantly slower than foo1 because it won't be able to exploit vectorization, and will involve more expensive address computations even if the input is contiguously stored in memory. To overcome this issue, one might propose to overload internally calling a template function, e.g.: </p><div class="fragment"><div class="line"><span class="comment">// in the .h:</span></div>
<div class="line"><span class="keywordtype">void</span> foo(<span class="keyword">const</span> Ref&lt;MatrixXf&gt;&amp; A);</div>
<div class="line"><span class="keywordtype">void</span> foo(<span class="keyword">const</span> Ref&lt;<a class="code" href="group__matrixtypedefs.html#ga731599f782380312960376c43450eb48">MatrixXf</a>,0,Stride&lt;&gt; &gt;&amp; A);</div>
<div class="line"> </div>
<div class="line"><span class="comment">// in the .cpp:</span></div>
<div class="line"><span class="keyword">template</span>&lt;<span class="keyword">typename</span> TypeOfA&gt; <span class="keywordtype">void</span> foo_impl(<span class="keyword">const</span> TypeOfA&amp; A) {</div>
<div class="line">    ... <span class="comment">// crazy code goes here</span></div>
<div class="line">}</div>
<div class="line"><span class="keywordtype">void</span> foo(<span class="keyword">const</span> Ref&lt;MatrixXf&gt;&amp; A) { foo_impl(A); }</div>
<div class="line"><span class="keywordtype">void</span> foo(<span class="keyword">const</span> Ref&lt;<a class="code" href="group__matrixtypedefs.html#ga731599f782380312960376c43450eb48">MatrixXf</a>,0,Stride&lt;&gt; &gt;&amp; A) { foo_impl(A); }</div>
</div><!-- fragment --><p>See also the following stackoverflow questions for further references:</p><ul>
<li><a href="http://stackoverflow.com/questions/21132538/correct-usage-of-the-eigenref-class">Correct usage of the Eigen::Ref&lt;&gt; class</a></li>
</ul>
<dl class="section see"><dt>See also</dt><dd><a class="el" href="classEigen_1_1PlainObjectBase.html#aaf9fcc07dc13f89cf71d4a4e2b220d24">PlainObjectBase::Map()</a>, <a class="el" href="group__TopicStorageOrders.html">Storage orders</a> </dd></dl>
</div>
<p>Inherits Eigen::RefBase&lt; Derived &gt;.</p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a037addaa81f13e5765e30a92d2c4f2b1"><td class="memTemplParams" colspan="2">template&lt;typename Derived &gt; </td></tr>
<tr class="memitem:a037addaa81f13e5765e30a92d2c4f2b1"><td class="memTemplItemLeft" align="right" valign="top">&#160;</td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classEigen_1_1Ref.html#a037addaa81f13e5765e30a92d2c4f2b1">Ref</a> (<a class="el" href="classEigen_1_1DenseBase.html">DenseBase</a>&lt; Derived &gt; &amp;expr)</td></tr>
<tr class="separator:a037addaa81f13e5765e30a92d2c4f2b1"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a037addaa81f13e5765e30a92d2c4f2b1"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a037addaa81f13e5765e30a92d2c4f2b1">&#9670;&nbsp;</a></span>Ref()</h2>

<div class="memitem">
<div class="memproto">
<div class="memtemplate">
template&lt;typename PlainObjectType , int Options, typename StrideType &gt; </div>
<div class="memtemplate">
template&lt;typename Derived &gt; </div>
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="classEigen_1_1Ref.html">Eigen::Ref</a>&lt; PlainObjectType, Options, StrideType &gt;::<a class="el" href="classEigen_1_1Ref.html">Ref</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="classEigen_1_1DenseBase.html">DenseBase</a>&lt; Derived &gt; &amp;&#160;</td>
          <td class="paramname"><em>expr</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">
<p>Implicit constructor from any dense expression </p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li><a class="el" href="Ref_8h_source.html">Ref.h</a></li>
</ul>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="namespaceEigen.html">Eigen</a></li><li class="navelem"><a class="el" href="classEigen_1_1Ref.html">Ref</a></li>
    <li class="footer">Generated on Thu Apr 21 2022 13:07:56 for Eigen by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
